package com.gxa.zuul.controller;

import com.gxa.zuul.pojo.GuaHaoYuan;
import com.gxa.zuul.pojo.YongHu;
import com.gxa.zuul.service.GuaHaoYuanServiceImpl;
import com.gxa.zuul.service.YongHuService;
import com.gxa.zuul.token.SkipJWT;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author thinknovo
 * @version 1.0
 * @description LoginController.java
 * @date 2021/1/7 11:00
 */
@RestController
@RequestMapping("user")
@Api(value = "登录验证",tags = "登录验证API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})
public class LoginController {
    @Resource
    private YongHuService yongHuService;

    // 读写分离
    // 当数据增\删\改的时候，默认插入数据库，然后缓存到redis中
    // 当完成查询的时候，则直接操作redis(扩展-当查询不到redis时，还是要查询一次数据库   数据穿透---雪崩风险)
    @SkipJWT
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ApiOperation(value = "用户登录接口（挂号员auth为9，医生8，护士7，收费员6）", notes = "姓名，密码，auth必传",
            httpMethod = "POST", response = String.class)
    public Map<String, Object> login(@RequestBody YongHu yonghu) {
        return yongHuService.login(yonghu);
    }

    @RequestMapping(value = "/reg", method = RequestMethod.POST)
    @ApiOperation(value = "用户注册接口（挂号员auth为9，医生8，护士7，收费员6）", notes = "id不传，当auth为8（医生）时才传keShiId、yiShengChuZhenJiHua、yiShengDangRiChuZhen、yiShengGuaHaoFei、yiShengLeiXing、yiShengZhenLiaoFei",
            httpMethod = "POST", response = String.class)
    public Map<String, Object> reg(@RequestBody YongHu yonghu) {
        return yongHuService.reg(yonghu);
    }

}
